exports.getLists = function (req, res) {
  // 拿到用户id
  console.log(req.body.score);
  const title = "getLists";
  res.render({ title, title });
};
// 个人排行名称
exports.getPerSonScore = async (req, res, next) => {
  const { id, team_id } = req.user;
  personResult = {};
  const sql_0 = `SELECT u.user_name, i.id, i.team_id,i.user_id, i.likes  FROM fa_images i 
  JOIN fa_users u ON  i.user_id = u.id WHERE i.user_id = ? AND i.team_id = ? AND i.type=2 `;
  const myPersonResult = await global.query(sql_0, [id, team_id]);
  if (myPersonResult.length > 0) {
    personResult = { currenInfo: myPersonResult[0] };
  }
  const sql = `SELECT u.user_name, i.id, i.team_id,i.user_id, i.likes  FROM fa_images i 
  JOIN fa_users u ON  i.user_id = u.id WHERE i.type=2`;
  global.query(sql).then((sqlResults) => {
    if (sqlResults.length > 0) {
      res.send({
        code: 200,
        msg: "success",
        data: { ...personResult, list: sqlResults },
      });
    } else {
      return res.cc("暂无个人排行信息");
    }
  });
};
// 获取团队分数的处理模块
exports.getTeamScore = (req, res, next) => {
  const sql = `SELECT t.team_id, SUM(i.likes) AS total_likes  FROM fa_images i
  JOIN fa_team t ON i.team_id = t.team_id GROUP BY t.team_id ORDER BY total_likes DESC;`;
  global.query(sql).then((sqlResults) => {
    console.log("sqlResults", sqlResults);
    if (sqlResults.length > 0) {
      res.send({
        code: 200,
        msg: "success",
        data: { list: sqlResults },
      });
    } else {
      return res.cc("暂无团队排行信息");
    }
  });
};
